﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using SuperSerialization;

namespace SuperSerialSamples
{
    class LiteralSamples
    {
        public static void SerializeInteger()
        {
            IntegerClass obj = new IntegerClass();
            obj.Value = 1234;
            Serializer.Serialize(Console.Out, obj);
            Console.WriteLine("\n");
        }

        public static void SerializeString()
        {
            StringClass obj = new StringClass();
            obj.Value = "hello world";
            Serializer.Serialize(Console.Out, obj);
            Console.WriteLine("\n");
        }

        public static void DeserializeInteger()
        {
            StringReader reader = new StringReader("SuperSerialSamples.LiteralSamples+IntegerClass { Value : 1234; }");
            IntegerClass obj = (IntegerClass)Serializer.Deserialize(typeof(IntegerClass), reader);
            Console.WriteLine(obj.ToString() + "\n");
        }

        public static void DeserializeString()
        {
            StringReader reader = new StringReader("SuperSerialSamples.LiteralSamples+StringClass { Value : \"hello world\"; }");
            StringClass obj = (StringClass)Serializer.Deserialize(typeof(StringClass), reader);
            Console.WriteLine(obj.ToString() + "\n");
        }

        class IntegerClass
        {
            public int Value = 0;

            public override string ToString()
            {
                return "IntegerClass: " + Value;
            }
        }

        class StringClass
        {
            public string Value = "default";

            public override string ToString()
            {
                return "StringClass: " + Value;
            }
        }
    }
}
